/**
 * 多页面配置
 * 循环pages文件夹里面的内容 动态添加多入口
 */

const glob = require('glob');
const path = require('path');

// 配置起止路径
const conf = {
  beginRoot: 'src'
};

exports.getEntries = function entry (globPath) {
  const entries = [];
  const pathList = glob.sync(globPath); // 找到文件夹下面的文件 [ 'src/pages/login/login.js' ]
  pathList.forEach(entry => {
    const pathObj = path.parse(entry); //{ root: '',dir: 'src/pages/login',base: 'login.js',ext: '.js',name: 'login' }
    const moduleName = pathObj.dir
      .split('/')
      .map((item, index) => {
        if (index === 0) return;
        if (index > 1) {
          return item.replace(/^\w{1}/, str => str.toUpperCase()); // 将第一个字母转成大写  ---- pagesLogin
        }
        return item;
      })
      .join('');
     let template = entry.split('.');
     template[1] = 'html';
     template = template.join('.')
    const item = {
      entry: `${entry}`,
      template: template,
      filename:`${pathObj.name}.html`,
      title:pathObj.name
    };
    entries.push(item); 
    /**
     * [ { 
      entry: 'src/pages/login/login.js',
      template: 'src/pages/login/login.html',
      filename: 'login.html',
      title: 'login' 
     } ]
     * */ 
  });
  return entries;
}